export default {
    name: "i-data",
    computed: {
        elements() {
            return this.customs.element.split("|");
        },
        elementValues() {
            return this.data.customs.element.split("|");
        }
    },
    data() {
        return {
            loading: false,
            data: {customs: {code: '', element: '', name: ''}},
            customs: {element: ''},
            elementModal: false,
            ruleValidate: {
                customer_id: [{required: true, message: '客户必须填写'}],
                code: [{required: true, message: '产品代码必须填写'}],
                title: [{required: true, message: '产品名称必须填写'}],
                gross_weight: [{required: true, type: 'number', message: '产品毛重必须填写'}],
                "brand": [{required: true, message: '品牌必须填写'}],
                "customs.code": [{required: true, message: '产品海关编码必须填写'}, {len: 10, message: "海关编码固定10位字符"}],
                "customs.unit": [{required: true, message: '申报单位必须填写'}, {len: 3, message: "申报单位固定3位字符"}],
                "customs.qy1": [{required: true, type: 'number', message: '第一法定数量必须填写'}],
                "customs.country": [{required: true, message: '原产国必须填写'}],
                "customs.name": [{required: true, message: '品名必须填写'}],
                "customs.net_weight": [{required: true, type: 'number', message: '净重必须填写'}],
                "customs.element": [{required: true, message: '申报要素必须填写'}, {
                    validator: (rule, value) => {
                        return this.elementValues.length === this.elements.length;
                    }, message: '申报要素格式不正确'
                }],
            }
        }
    },
    methods: {
        elementModalOk() {
            if (this.elementValues.length > this.elements.length) {
                this.$Notice.error({
                    title: '错误提示',
                    desc: "申报要素不对！！"
                });
                return;
            }

            if (this.elementValues.length < this.elements.length) {
                let count = this.elements.length - this.elementValues.length;
                for (let $i = 0; $i < count; $i++) {
                    this.elementValues.push('');
                }
            }

            this.data.customs.element = this.elementValues.join("|");
        },
        changeHsCode(item) {
            this.customs = item;
            if(this.data.customs.name === ''){
                this.data.customs.name = this.data.name;
            }
            this.data.customs.unit1 = item.unit1;
            this.data.customs.unit2 = item.unit2;

        }
    }
}
